<?
// ********************************
//
//	get metadata from common list
//
// ********************************

class VALUE {

	var $id_data;
	var $id_parent;
	var $assoc;
	var $name;
	var $data;
	
	var $res;
	
	function VALUE() {

		$this->data = '';
		$this->res = 255;
	}
	
	function init($id_data, $parent, $name, $assoc='') {

		$this->id_data = $id_data;
		$this->id_parent = $parent;
		$this->assoc = $assoc;
		$this->name = $name;
		
		$this->res = $this->fetch();
		return ! (bool) $this->res;
	}
	
	function fetch() {
		
		if ($d = dataset('db_item', tb('data'), 	// get records with empty 'assoc' (i.e. for all langs) or with corresponding 'assoc'
				"(id_data={$this->id_data}) AND
				(id_parent={$this->id_parent}) AND
				(name='{$this->name}') AND
				((assoc IS NULL) OR (assoc='') OR INSTR(assoc,'{$this->assoc}')!=0)" )) {

			$this->data = $d->data['value'];
		
			return 0;
		}
	}
}

?>